/*--------------------劳务模块.人员管理--ly-----------------*/
/*--------------------劳务人员新增功能 lb_people_add.html------------------*/

layui.use(['form', 'layer'], function() {
	$ = layui.jquery;
	var form = layui.form,
		layer = layui.layer;

	//自定义验证规则
	form.verify({
		name: function(value) {
			if(value.length < 5) {
				return '昵称至少得5个字符啊';
			}
		},
		idcard: function(value) {
			if(value.length != 18) {
				return '身份证号码格式错误';
			}
		},
	});

	var url = laborport + "/LabourController/insert"; //请求数据url
	//post请求
	var postResult = (function() {
		var name = $('#L_name').val(); //劳务人员名称
		var birthday = $('#L_birthday').val(); //生日
		var age = $('#L_age').val(); //年龄
		var gender = $('#L_gender').val(); //性别
		var ismonitor = $('#L_ismonitor').val(); //是否班长
		var idcard = $('#L_idcard').val(); //身份证号码
		var presentaddr = $('#L_presentaddr').val(); //现居住地址
		var familyaddr = $('#L_familyaddr').val(); //家庭地址
		var photourl = $('#L_photourl').val(); //照片
		var qrcodeurl = $('#L_qrcodeurl').val(); //二维码
		$.post(url, {
			name: name,
			birthday: birthday,
			age: age,
			gender: gender,
			ismonitor: ismonitor,
			idcard: idcard,
			presentaddr: presentaddr,
			familyaddr: familyaddr,
			photourl: photourl,
			qrcodeurl: qrcodeurl,
			companyid:"160b99b7-0878-4c9b-b988-24b0081ed845",
			jobid:"463cbbc0-51d0-4b58-affb-d29159ab2fef",
			teamid:"d06f2c17-66a8-4046-9a5d-3aaa8bcf9709",
			state:"1",
		}, function(result) {
			if(result.code == '0') {
				console.log(result);
				layer.alert("增加成功", {
					icon: 6
				}, function() {
					// 获得frame索引
					var index = parent.layer.getFrameIndex(window.name);
					//关闭当前frame
					parent.layer.close(index);
				});
			} else {
				layer.alert("服务器繁忙，稍后再试", {
					icon: 5
				}, function() {
					// 获得frame索引
					var index = parent.layer.getFrameIndex(window.name);
					//关闭当前frame
					parent.layer.close(index);
				});
			}
		});
	})
	//监听提交
	form.on('submit(add)', function(data) {
		console.log(data);
		//发异步，把数据提交给php
		postResult();
		return false;
	});
});